<template>
  <div class="search-form">
    <div class="search-content" :style="{
          'padding-right': `calc(100vw - ${rightIconInfo.left - 15}px)`,
          'padding-top': `${rightIconInfo.top}px`,
        }">
      <div class="main-content" :style="{ height: `${rightIconInfo.height}px` }">
        <div>
          <div class="icon-content">
            <uni-icons type="back" size="20" @click="$pageBack" />
          </div>
          <div class="input-content">
            <uni-easyinput confirmType="search" v-model="keywords" :placeholder="placeholder" @confirm="search" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'SearchForm',
    components: {},
    props: {
      placeholder: {
        type: String,
        default: '',
      },
    },
    data() {
      return {
        rightIconInfo: {},
        keywords: '',
      };
    },
    computed: {},
    watch: {},
    mounted() {
    },
    created() {
      this.init();
    },
    methods: {
      init() {
        this.rightIconInfo = uni.getMenuButtonBoundingClientRect();
        console.log(this.rightIconInfo);
      },
      search() {
        this.$emit('search', { keywords: this.keywords });
      },
    },
  };
</script>

<style lang="scss" scoped>
  .search-form {
    border-bottom: 1px solid #eeeeee;
    .search-content {
      background-color: white;
      padding: 15px;
      .main-content {
        position: relative;
        > div {
          position: absolute;
          top: 50%;
          transform: translateY(-50%);
          display: flex;
          align-items: center;
          width: 100%;
          .input-content {
            flex: 1;
            margin-left: 10px;
          }
        }
      }
    }
  }
</style>
